﻿@page
@model IndexModel
@{
    ViewData["Title"] = "Order page";
}



<div>
    <table class="table table-striped table-hover">
        <thread>
            <tr>
                <th>序号</th>
                <th>单号</th>
                <th>销售额</th>
                <th>总量</th>
                <th>颜色</th>
            </tr>
        </thread>
        <tbody id="table"></tbody>
    </table>
</div>




@section Scripts{


    <script id='tmp' type="text/html">
        {{if list.length>=0}}
        {{each list}}
        <tr>
            <td>{{$index+1}}</td>
            <td>{{$value.orderNo}}</td>
            <td>{{$value.sumPrice}}</td>
            <td>{{$value.totalAmount}}</td>
            <td>{{$value.colors.substr(0,50)}}</td>
        </tr>
        {{/each}}
        {{else}}
        <tr>
            <td>没有数据</td>
        </tr>
        {{/if}}
    </script>


    <script>
        function req(data, callback) {
            $.ajax({
                url: data.url,
                type: data.type,
                crossDomain: true,
                beforeSend: function (xhr) {
                },
                data: data.data,
                success: function (data) {
                    if (typeof callback === 'function') {
                        callback(data);
                        console.log(data, "成功")
                    }
                },
                error: function (err) {
                    console.log(`get error ${JSON.stringify(err)}`);
                }
            });
        }
        // todo color 使用set 去重
        $(function () {
            var param = {
                url: 'api/Order/detail',
                type: 'get'
            }
            req(param, function (cdata) {
                var data = {
                    list :cdata
                }
                $('#table').html(template('tmp', data));
            })
        })
    </script>
}